#include<iostream>
#include<map>
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
int arr[N];
LL s[N];
int cnt[N];
int hash1[N];
int n, k;
map<LL, int>mp;
int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		s[i] = s[i - 1] + arr[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= 30; j++) {
			if (s[i] - (int)pow(k, j) >= 0) {
				mp[s[i] - (int)pow(k, j)] = i;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= n - 1; i++) {
		if (mp[s[i]] > i ) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}